﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ST.Model;
using ST.Bll;
using ST.Common;

namespace ST.Web.admin
{
    public partial class CategoryEdit :BasePage
    {
        protected Category category;
        protected CategoryBLL bll = new CategoryBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) return;
            if (IsEdit)
            {
                if (string.IsNullOrEmpty(PrimaryKey))
                    return;
                category = bll.GetCategory(Convert.ToInt32(this.PrimaryKey));
                this.tbCategoryName.Text = category.CategoryName;
                this.tbOrderIndex.Text = category.OrderIndex.ToString();                
            }
            else {
                category = new Category();
            }
            
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            category.CategoryName = this.tbCategoryName.Text.Trim();
            category.OrderIndex = Convert.ToInt32(this.tbOrderIndex.Text);
            if (IsEdit)
            {
                if (bll.UpdateCategory(category))
                {
                    MessageBox("更新成功!");
                }
            }
            else
            {
                bll.CreateCategory(category);
                MessageBox("保存成功");
            }
        }
    }
}
